package com.app.common;

import java.util.Random;

/**
 * @ClassName: RandomNumUtils
 * @Description:
 * @Author fy
 * @Date 2023/07/18 17:34
 */
public class RandomNumUtils {

    public static String generateSoleName() {
        String tmpResult;
        StringBuilder soleResult = new StringBuilder();
        //生成7位随机
        for (int i = 1; i <= 6; i++) {
            //判断产生的随机数是0还是1，是0进入if语句用于输出数字，是1进入else用于输出字符
            int mark = Math.random() >= 0.5 ? 1 : 0;
            if (0 == mark) {
                Random random = new Random();
                //产生0-9数字
                tmpResult = random.nextInt(10) + "";
            } else {
                //'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'
                //'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o','p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
                char[] englishNumArray = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
                Random random = new Random();
                int sub = random.nextInt(englishNumArray.length);
                //产生A——z字符
                tmpResult = englishNumArray[sub] + "";
            }
            soleResult.append(tmpResult);
        }
        return soleResult.toString();
    }

    public static String getCode() {
        String tmpResult;
        String Result;
        StringBuilder soleResult = new StringBuilder();
        Random random = new Random();
        char[] englishNumArray = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
        int sub = random.nextInt(englishNumArray.length);
        //产生A——z字符
        tmpResult = englishNumArray[sub] + "";
        //生成5位随机
        for (int i = 1; i < 6; i++) {
            //产生0-9数字
            Result = random.nextInt(10) + "";
            soleResult.append(Result);
        }
        return tmpResult+soleResult;
    }

    public static void main(String[] args) {
        System.out.println(getCode());
    }
}